<?php
class clerror{
    public static $cltab;
	public function __construct(){
	    self::$cltab=new Cltable();	
		$this->setErrorHandler();
	}
	public function __destruct(){}	
	public function setErrorHandler(){
	    set_error_handler ('clerror::errorHandler');
    }
	public static function errorHandler (
	$error_level, $error_message, $file, $line,$error_context) {
		//global $tab;
    switch ($error_level) {
		//提醒级别
        case E_NOTICE:
		 $error_type = 'E_NOTICE';
            break;
        case E_USER_NOTICE:
            $error_type = 'E_USER_NOTICE';
            break;
		
		//警告级别
        case E_WARNING:
		$error_type = 'E_WARNING';
            break;
        case E_USER_WARNING:
            $error_type = 'E_USER_WARNING';
            break;
		
		//错误级别
        case E_ERROR:
		    $error_type = 'E_ERROR';
            break;
        case E_USER_ERROR:
            $error_type = 'E_USER_ERROR';
            $EXIT = TRUE;
            break;
		
		//其他未知错误
        default:
            $error_type = '['.$error_level.']';
            $EXIT = TRUE;
            break;
    }
 
	if(array_key_exists("php_errormsg", $error_context)){
		$php_errormsg=$error_context['php_errormsg'];
	}else{
	    $php_errormsg='';	
	}
	
	self::$cltab->export (array(
	'level'=>$error_level,
	'type'=>$error_type,
	'message'=>$error_message,
	'file'=>$file, 
	'line'=>$line,
	'error_context'=> $php_errormsg
	 ));
     //return true 隐藏系统的报错;
        return true;
     }
}
?>